<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增问答')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-activitytype-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">问题：</label>
            <div class="col-sm-8">
                <input name="qname" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">回答简介：</label>
            <div class="col-sm-8">
                <input name="object" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否展示：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('qa_show')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="isShow" th:value="${dict.dictValue}"
                           th:checked="${dict.default}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <input id="details" name="details" type="hidden">
            <label class="col-sm-3 control-label">详情：</label>
            <div class="col-sm-8">

                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <button id="edit" class="btn btn-primary btn-xs m-l-sm" onclick="editDetails()" type="button">编辑</button>
                        <button id="save" class="btn btn-primary  btn-xs" onclick="saveDetails()" type="button">保存</button>
                    </div>
                    <div class="ibox-content" id="eg">

                        <div class="click2edit wrapper">

                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">排序：</label>
            <div class="col-sm-8">
                <input name="sort" class="form-control" type="text" required>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<th:block th:include="include :: summernote-js" />
<script type="text/javascript">
    $(document).ready(function () {
        $('.summernote').summernote({
            lang: 'zh-CN'
        });
    });
    var editDetails = function () {
        $("#eg").addClass("no-padding");
        $('.click2edit').summernote({
            lang: 'zh-CN',
            focus: true
        });
    };
    var saveDetails = function () {
        $("#eg").removeClass("no-padding");
        var aHTML = $('.click2edit').summernote('code');
        $('.click2edit').summernote('destroy');
        $("#details").val(aHTML)
    };
    var prefix = ctx + "system/activitytype"
    $("#form-activity-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-activitytype-add').serialize());
        }
    }

    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            , url: '/common/upload' //改成您自己的上传接口
            , done: function (res) {
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $("#demoText1 ").html("<img src='" + res.url + "' style='width:80px;height:80px;'>");
                $("#mainUrl").val(res.url);
                $("#headRealUrl").val(res.realPath);
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })

</script>
</body>
</html>